import { ElSelect, ElInputNumber, ElInput, ElDatePicker, ElOption, ElRadioGroup, ElRadio } from 'element-plus'
import { h } from 'vue'
import { formOptions } from './formOptions'
import { FormItem } from './types'
// 表单字段配置（按业务模块分组，清晰可维护）
export const formRows: Array<FormItem[]> = [
  // 基础信息行
  [
    {
      label: '姓名',
      field: 'name', // 唯一字段名，避免重复
      component: ElInput,
      span: 6,
      placeholder: '请输入姓名'
    },
    {
      label: '性别',
      field: 'gender',
      component: ElSelect,
      type: 'select',

      span: 6,
      props: { options: formOptions.gender },
      placeholder: '请选择性别',
      visible: {
        conditions: [
          { field: "name", operator: "===", value: '18' }
        ],
        logic: "AND"
      },
      dependsOn: ["name", "gender"],
      events: {
        change: (value: any) => {
          console.log(value);
        }
      }
    },
    {
      label: '出生日期',
      field: 'birthDate',
      component: ElDatePicker, // 日期用日期选择器
      span: 6,
      props: { type: 'date', valueFormat: 'YYYY-MM-DD' },
      placeholder: '请选择出生日期'
    },
    {
      label: '年龄',
      field: 'age',
      component: ElInputNumber, // 数字用数字输入框
      span: 6,
      props: { min: 0, max: 150 },
      placeholder: '请输入年龄'
    }
  ],
  // 身份信息行
  [
    {
      label: '国籍',
      field: 'nationality',
      component: ElInput,
      span: 6,
      placeholder: '请输入国籍'
    },
    {
      label: '民族',
      field: 'ethnicity',
      component: ElInput,
      span: 6,
      placeholder: '请输入民族'
    },
    {
      label: '新生儿出生体重',
      field: 'birthWeight',
      component: ElInputNumber,
      span: 6,
      props: { min: 0, step: 0.01, precision: 2 },
      placeholder: '请输入体重(kg)'
    },
    {
      label: '新生儿入院体重',
      field: 'admissionWeight',
      component: ElInputNumber,
      span: 6,
      props: { min: 0, step: 0.01, precision: 2 },
      placeholder: '请输入体重(kg)'
    }
  ],
  // 地址信息行
  [
    {
      label: '出生地',
      field: 'birthPlace',
      component: ElInput,
      span: 12,
      placeholder: '请输入出生地'
    },
    {
      label: '籍贯',
      field: 'nativePlace',
      component: ElInput,
      span: 12,
      placeholder: '请输入籍贯'
    }
  ],
  // 证件与状态行
  [
    {
      label: '身份证',
      field: 'idCard',
      component: ElInput,
      span: 6,
      placeholder: '请输入18位身份证号'
    },
    {
      label: '职业',
      field: 'occupation',
      component: ElInput,
      span: 6,
      placeholder: '请输入职业'
    },
    {
      label: '婚姻状态',
      field: 'maritalStatus',
      component: ElSelect,
      type: 'select',
      span: 12,
      props: { options: formOptions.marital },
      placeholder: '请选择婚姻状态',
      visible: {
        conditions: [
          { field: "age", operator: ">", value: 18 },
          { field: "gender", operator: "===", value: "male" }
        ],
        logic: "AND"
      }
    }
  ],
  // 现住址信息行
  [
    {
      label: '现住址',
      field: 'currentAddress', // 替换模糊的xzz，用明确命名
      component: ElInput,
      span: 12,
      placeholder: '请输入现住址'
    },
    {
      label: '电话',
      field: 'phone', // 替换dh
      component: ElInput,
      span: 6,
      placeholder: '请输入联系电话'
    },
    {
      label: '邮政',
      field: 'postalCode', // 替换yz
      component: ElInput, // 邮编是输入框而非选择器
      span: 6,
      placeholder: '请输入邮政编码'
    }
  ],
  // 户口地址信息行
  [
    {
      label: '户口地址',
      field: 'registeredAddress',
      component: ElInput,
      span: 18,
      placeholder: '请输入户口地址'
    },
    {
      label: '邮编',
      field: 'registeredPostal',
      component: ElInput,
      span: 6,
      placeholder: '请输入邮政编码'
    }
  ],
  // 工作单位信息行
  [
    {
      label: '工作单位及地址',
      field: 'workUnit',
      component: ElInput,
      span: 12,
      placeholder: '请输入工作单位及地址'
    },
    {
      label: '单位电话',
      field: 'workPhone',
      component: ElInput,
      span: 6, // 调整span使行总跨度为24（12+12）
      placeholder: '请输入单位电话'
    },
    {
      label: '邮编',
      field: 'registeredPostal',
      component: ElInput,
      span: 6,
      placeholder: '请输入邮政编码'
    }
  ],
  // 联系人信息行
  [
    {
      label: '联系人姓名',
      field: 'contactName',
      component: ElInput,
      span: 6,
      placeholder: '请输入联系人姓名'
    },
    {
      label: '关系',
      field: 'contactRelation',
      component: ElInput,
      span: 6,
      placeholder: '请输入关系（如：父子、夫妻）'
    },
    {
      label: '地址',
      field: 'contactAddress',
      component: ElInput,
      span: 6,
      placeholder: '请输入联系人地址'
    },
    {
      label: '电话',
      field: 'contactPhone',
      component: ElInput,
      span: 6,
      placeholder: '请输入联系人电话'
    }
  ],
  // 入院基本信息行
  [
    {
      label: '入院途径',
      field: 'admissionWay',
      component: ElRadioGroup,
      span: 12,
      props: { options: formOptions.admissionWay },
      slots: {
        default: () => formOptions.admissionWay.map(option =>
          h(ElRadio, {
            key: option.value,  // 必须提供唯一key
            value: option.value
          }, option.label)
        )
      }
    },
    {
      label: '病人来源',
      field: 'patientSource',
      component: ElSelect,
      span: 6,
      props: { options: formOptions.patientSource },
      slots: {
        default: () => formOptions.admissionWay.map(option =>
          h(ElOption, {
            key: option.value,  // 必须提供唯一key
            value: option.value
          }, option.label)
        )
      }
    }
  ],
  // 入院详细信息行
  [
    {
      label: '入院日期',
      field: 'admissionDate',
      component: ElDatePicker, // 日期用日期选择器
      span: 6,
      props: { type: 'datetime', valueFormat: 'YYYY-MM-DD HH:mm' },
      placeholder: '请选择入院日期'
    },
    {
      label: '入院科别',
      field: 'admissionDept',
      component: ElInput,
      span: 6,
      placeholder: '请输入入院科别'
    },
    {
      label: '入院病房',
      field: 'admissionWard',
      component: ElInput,
      span: 6,
      placeholder: '请输入病房'
    }
  ],
  // 转科信息行
  [
    {
      label: '转科',
      field: 'transferDept',
      component: ElInput,
      span: 24, // 单行内容用24跨度更合理
      placeholder: '请输入转科记录（如有）'
    }
  ],
  // 出院信息行
  [
    {
      label: '出院日期',
      field: 'dischargeDate',
      component: ElDatePicker,
      span: 6,
      props: { type: 'datetime', valueFormat: 'YYYY-MM-DD HH:mm' },
      placeholder: '请选择出院日期'
    },
    {
      label: '出院科别',
      field: 'dischargeDept',
      component: ElInput,
      span: 6,
      placeholder: '请输入出院科别'
    },
    {
      label: '病房',
      field: 'dischargeWard',
      component: ElInput,
      span: 6,
      placeholder: '请输入病房'
    },
    {
      label: '实际住院天数',
      field: 'hospitalizationDays',
      component: ElInputNumber, // 天数是数字
      span: 6,
      props: { min: 0 },
      placeholder: '请输入住院天数'
    }
  ],
  // 诊断信息行
  [
    {
      label: '门诊诊断',
      field: 'outpatientDiagnosis',
      component: ElInput,
      span: 12,
      placeholder: '请输入门诊诊断'
    },
    {
      label: '疾病编码',
      field: 'diseaseCode',
      component: ElInput,
      span: 6,
      placeholder: '请输入疾病编码'
    },
    {
      label: '门诊医生',
      field: 'outpatientDoctor',
      component: ElInput,
      span: 6,
      placeholder: '请输入门诊医生'
    }
  ]
]